<?php
$this->useClass("Action_Community_FeedHandler");
class Action_Node_ShowFeedRss extends Action_Community_FeedHandler
{
	public function getFeedModel() {
		$this->rh->UseClass("AggregatedModel_Feed_FeedInterface");
		$this->rh->UseClass("AggregatedModel_Feed_ReaderItems");

		return new AggregatedModel_Feed_ReaderItems();
	}

	protected function init() {
		parent::init();
		$this->rh->UseClass("RL_URLGenerator");
	}

	public function process ()
	{
		$aa = &$this->aa;
		$this->model->setModelParams("page_citems", 20);
		$this->model->doStuff();

		$view = $this->rh->views->findByName($this->params['view']);
		$view->data = $aa->template_data;
		$items = $this->model->getItems();

		if ($items) {
			foreach($items as $k=>$v) {
				$date = clone $v['post']['ctime'];
				$items[$k]['date'] = $date;
				$items[$k]['post_url'] = $this->hrefPost($v);
			}
			$view->getMeta()->setLastModified($items[0]['date']->mktime());
			$view->data['items'] = $items;
		} else $view->data['message'] = "В этой ленте нет сообщений.";

		$this->rh->response->setContent( $view );
	} // end of function process

	public function hrefPost ($item)
	{
		$ug = new RL_URLGenerator($this->rh->router->getRule("showitem")); //
		$ug->setRouter($this->rh->router);
		$ug->setParams(array(
			"community_url"=>$item['community']['url'],
			"id_item"=>$item['post']['oid'],
			)
		);
		return $ug->generateUrl();
	} // end of method hrefPost

}
